<?php
/**
 * @brief 
 *
 * @license		http://www.gnu.org/licenses/gpl-3.0.txt GNU General Public License
 * @copyright	2008 David Singer
 * @author		David Singer <david@ramaboo.com>
 * @version		1.0.0
 */

require_once('../../includes/common.php');

try {
	// check requried params
	if (!isset($_POST['type'])) {
		throw new Exception("Type is required.");
	}
	$type = htmlentities(strtoupper(trim($_POST['type'])));
	
	if (!isset($_POST['zone'])) {
		throw new Exception("Zone is required.");
	}
	$zone = htmlentities(strtolower(trim($_POST['zone'])));
	
	$json = array(); 
	$record = new Record;
	
	$record->setType($type);
	$record->setZone($zone);
	$record->save();
	$id = $record->getId();
	
	$json['success'] = true;
	$json['msg'] = "Record $id added.";
} catch (Exception $e) {
	$json['success'] = false;
	$json['msg'] = $e->getMessage();
}

$output = json_encode($json);
header_no_cache(strlen($output), 'application/json');
echo $output;
?>